package com.qf.petservice_api.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration //配置类
@EnableSwagger2 //启用Swagger
public class SwaggerConfig {
    /**
     * 构建文档的基本信息
     */
    public ApiInfo createApi(){
        return new ApiInfoBuilder().
                title("宠物服务项目的接口文档")
                .description("宠物服务项目项目是由我们六人共同完成的")
                .contact(new Contact("千锋郑州Java","http://www.qfedu.com","xingfei_work@163.com"))
                .version("1.0.0").build();
    }

    /**
     * 就是ioc创建实例 修饰方法 方法必须返回对象
     */
    @Bean //等同于<bean> 配合@Configuration 会把方法的返回值存储到IOC容器
    public Docket createDocket(){
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(createApi())
                .select().apis(RequestHandlerSelectors.
                        withClassAnnotation(Api.class)).build();
    }
}
